import 'package:abc/page/alipay_page.dart';
import 'package:abc/view/PaymentResultDialogContent.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class CoinRechargeController extends GetxController {
  // 充值金额选项
  final List<Map<String, dynamic>> rechargeOptions = [
    {'coins': '10', 'price': '¥ 20'},
    {'coins': '20', 'price': '¥ 50'},
    {'coins': '40', 'price': '¥ 60'},
    {'coins': '100', 'price': '¥ 100'},
    {'coins': '300', 'price': '¥ 300'},
    {'coins': '500', 'price': '¥ 500'},
  ];

  // 支付方式选项
  final List<Map<String, dynamic>> paymentMethods = [
    {'name': '微信', 'icon': 'icon_wechat'},
    {'name': '支付宝', 'icon': 'icon_zfb'},
  ];

  // 当前选中的充值金额索引
  final RxInt _selectedRechargeIndex = 0.obs;
  int get selectedRechargeIndex => _selectedRechargeIndex.value;
  set selectedRechargeIndex(int value) => _selectedRechargeIndex.value = value;

  // 当前选中的支付方式索引
  final RxInt _selectedPaymentIndex = 0.obs;
  int get selectedPaymentIndex => _selectedPaymentIndex.value;
  set selectedPaymentIndex(int value) => _selectedPaymentIndex.value = value;

  // 选择充值金额
  void selectRechargeOption(int index) {
    _selectedRechargeIndex.value = index;
  }

  // 选择支付方式
  void selectPaymentMethod(int index) {
    _selectedPaymentIndex.value = index;
  }

  // 获取选中的充值金额信息
  Map<String, dynamic> get selectedRechargeOption =>
      rechargeOptions[selectedRechargeIndex];

  // 获取选中的支付方式信息
  Map<String, dynamic> get selectedPaymentMethod =>
      paymentMethods[selectedPaymentIndex];

  // 处理支付
  void handlePayment() {
    final recharge = selectedRechargeOption;
    final payment = selectedPaymentMethod;
    if(payment['name'] == '支付宝') {
      Get.to(() => const AlipayPage());
    }else{
  Get.generalDialog(
        // context: context,
        barrierLabel: "支付结果确认",
        barrierDismissible: false, // 允许点击外部关闭
        barrierColor: Color(0x99000000), // 半透明背景
        transitionDuration: const Duration(milliseconds: 300),
        pageBuilder: (context, anim1, anim2) {
          return const PaymentResultDialogContent();
        },
      );
    }

  }
}
